import { ActionType, SelectType, TodoTaskType } from '../reducer/todo';

// 2.6.让Action创建函数，指定返回类型为ActionType
// 💥使用分开指定，指定返回值类型
export const updateByIdAction = (id: number): ActionType => {
  // 1.2 定义action创建函数
  return {
    type: 'todo/updateById',
    payload: id,
  };
};

// 3.3 action创建函数
export const delByIdAction = (id: number): ActionType => {
  return {
    type: 'todo/delById',
    payload: id,
  };
};

// 4.3 定义action创建函数
export const clearDoneAction = (): ActionType => {
  return {
    type: 'todo/clearDone',
  };
};
// 6.3 封装action创建函数
export const addNewTaskAction = (newTodo: TodoTaskType): ActionType => {
  return {
    type: 'todo/add',
    payload: newTodo,
  };
};

// 8.3 封装action创建函数
export const updateTypeAction = (type: SelectType): ActionType => {
  return {
    type: 'todo/updateType',
    payload: type,
  };
};

// 11.3 定义action创建函数
export const toggleAllAction = (checked: boolean): ActionType => {
  return {
    type: 'todo/toggleAll',
    payload: checked,
  };
};
